package www.com.utils;


/**
 * ArcResponse : 通用响应对象, 封装数据如下
 *
 * {"meta":{"code":200,"message":"创建成功"},"data":{"id":"5308e9c2-a4ce-4dca-9373-cc1ffe63d5f9","name":"Apple Watch SPORT","description":"Sport 系列的表壳材料为轻巧的银色及深空灰色阳极氧化铝金属，强化 Ion-X 玻璃材质为显示屏提供保护。搭配高性能 Fluoroelastomer 表带，共有 5 款缤纷色彩。"}}
 *
 */
public class ArcResponse<T> {

    public static final int SUCC = 0;
    public static final int FAIL = -1;

    /**
     * 状态码
     */
    private int code=-1;
    /**
     * 状态描述
     */
    private String msg="";
    /**
     * 返回数据
     */
    private T data;

    public ArcResponse() {

    }
    public ArcResponse(int code, String message) {
        this(code, message,null);
    }

    public ArcResponse(int code, String message, T data) {
        this.code= code;
        this.msg= message;
        this.data = data;
    }

    public int getCode() {
		return code;
	}

	public void setCode(int pcode) {
        code = pcode;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String pMsg) {
		msg = pMsg;
	}

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> ArcResponse<T> createBySuccess (String msg) {
        ArcResponse<T> arcResponse = new ArcResponse<>();
        arcResponse.setCode(ArcResponse.SUCC);
        arcResponse.setMsg(msg);
        return arcResponse;
    }

    public static <T> ArcResponse<T> createBySuccess (String msg , T data) {
        ArcResponse<T> arcResponse = new ArcResponse<>();
        arcResponse.setCode(ArcResponse.SUCC);
        arcResponse.setMsg(msg);
        arcResponse.setData(data);
        return arcResponse;
    }

    public static <T> ArcResponse<T> createByFail (String msg){
        ArcResponse<T> arcResponse = new ArcResponse<>();
        arcResponse.setCode(ArcResponse.FAIL);
        arcResponse.setMsg(msg);
        return arcResponse;
    }

    public static <T> ArcResponse<T> createByCustom (String msg , int code, T data) {
        ArcResponse<T> arcResponse = new ArcResponse<>();
        arcResponse.setCode(code);
        arcResponse.setMsg(msg);
        arcResponse.setData(data);
        return arcResponse;
    }

    public static <T> ArcResponse<T> createByCustom (String msg , int code) {
        ArcResponse<T> arcResponse = new ArcResponse<>();
        arcResponse.setCode(code);
        arcResponse.setMsg(msg);
        return arcResponse;
    }

}
